﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YNCNumberSys.db;

namespace YNCNumberSys.DbDal
{
    public class wxApl
    {
        private CommandManager commandManager = new CommandManager();
        private ConnectionManager connectionManager = new ConnectionManager();
        public int BuildWxPaperCode(List<string> SQL)
        {
            return commandManager.update(connectionManager.getConnection(), SQL);
        }

        public DataTable CheckFileNo(string machineNo,
                   string aNo,
                   string usm)
        {
            string sql = string.Format(@"exec [dbo].[YNC_AllocateFileNoCheckWx] '{0}','{1}','{2}'", machineNo, aNo, usm);
            return commandManager.ExecuteNonQuery(connectionManager.getConnection(), sql, @"图号检查");
        }

        /// <summary>
        /// 执行存储过程
        /// </summary>
        /// <param name="machineNo">机床号</param>
        /// <param name="aNo">A号，暂时没用</param>
        /// <param name="paperSeries">图纸系列，如4C</param>
        /// <param name="userCode">用户号</param>
        /// <param name="wx">1，外协，0 非外协</param>
        /// <param name="rang">图号的个数</param>
        /// <returns></returns>
        public DataTable ExecuteStoredProcedure(
            string machineNo,
            string aNo,
            string partName,
            string spec,
            string usm,
            string auditor,
            int wx,
            string wxDw)
        {
            string sql = string.Format(@"exec [dbo].[YNC_AllocateFileNoWx] '{0}','{1}','{2}','{3}',{4},'{5}',{6},{7},'{0}'",
                machineNo, aNo, partName, spec, usm, auditor, 1, wx, wxDw);
            return commandManager.ExecuteNonQuery(connectionManager.getConnection(), sql, @"图号");
        }

        /// <summary>
        /// 执行存储过程，从最大已经分配的图纸号。
        /// </summary>
        /// <param name="machineNo">机床号</param>
        /// <param name="aNo">A号，暂时没用</param>
        /// <param name="paperSeries">图纸系列，如4C</param>
        /// <param name="userCode">用户号</param>
        /// <param name="wx">1，外协，0 非外协</param>
        /// <param name="rang">图号的个数</param>
        /// <returns></returns>
        public DataTable ExecuteStoredProcedureMaxIncrease(
            string machineNo,
            string aNo,
            string partName,
            string spec,
            string usm,
            string auditor,
            int wx,
            string wxDw)
        {
            //            [dbo].[YNC_AllocateFileNoMaxIncrease]
            //@machineNo nvarchar(50)='' 0,        --设置默认值
            //@aNo    nvarchar(50)='' 1,             --设置默认值
            //@partName nvarchar(50)='' 2,  
            //@partSpec nvarchar(50)='' 3, 
            //@usm nvarchar(50) 4,              --设置默认值
            //@auditor nvarchar(50)5,            --审核人
            //@protect int=1 6,
            //@wx int=0 7,
            //@fc int=0 8,--4C 1,其他0
            //@wxDw nvarchar(max)=''
            string sql = string.Format(@"exec [dbo].[YNC_AllocateFileNoMaxIncreaseWx] '{0}','{1}','{2}','{3}',{4},'{5}',{6},{7},'{8}'",
                machineNo, aNo, partName, spec, usm, auditor, 1, wx, wxDw);
            return commandManager.ExecuteNonQuery(connectionManager.getConnection(), sql, @"图号");
        }
    }
}
